﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (txtProcStart.Text == "Timer setzen") {
                TimerSetzen.PerformClick();
            }
            timer1.Enabled = true;
        }

        private void button2_Click(object sender, EventArgs e)
        {

            DateTime later = DateTime.Now.AddHours(Convert.ToInt32(txtDelay.Text));
            txtProcStart.Text = Convert.ToString(later);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            TimeSpan travelTime = DateTime.Now - Convert.ToDateTime(txtProcStart.Text);
            this.Text = "n =" + Convert.ToString(travelTime);

            if (DateTime.Now >= Convert.ToDateTime(txtProcStart.Text)) {
                timer1.Enabled = false;
                
                Process proThis = new Process();
                ProcessStartInfo psiThis = new ProcessStartInfo("rundll32.exe", "powrprof.dll, SetSuspendState");
                psiThis.RedirectStandardOutput = true;
                psiThis.UseShellExecute = false;
                proThis.StartInfo = psiThis;
                proThis.Start();
                proThis.WaitForExit();
            }

        }

    }
}
